package org.timemachine.action.facadeBean;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.timemachine.action.facade.ForwardEntityFacade;
import org.timemachine.model.base.ForwardEntity;

@Stateless
public class ForwardEntityFacadeBean implements ForwardEntityFacade {

	@PersistenceContext
	private EntityManager entityManager;


	@Override
	public void createForwardEntity(ForwardEntity forwardEntity) {		
		entityManager.persist(forwardEntity);
	}

	@Override
	public ForwardEntity findById(Long forwardEntityId) {
		return entityManager.find(ForwardEntity.class, forwardEntityId);
	}

	@Override
	public void remove(ForwardEntity forwardEntity) {
		entityManager.remove(forwardEntity);
	}

	@Override
	public ForwardEntity findByForwardChangeInfoId(Long forwardChangeInfoId) {
		return (ForwardEntity) entityManager.createQuery("select f from ForwardEntity f where f.forwardChangeInfo.id = :id ")
							.setParameter("id", forwardChangeInfoId)
							.getSingleResult();	
	}

}
